//
//  VipInfpPersonTableViewCell.m
//  fitnessmanage
//
//  Created by wujian on 2017/10/29.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "VipInfpPersonTableViewCell.h"

@interface VipInfpPersonTableViewCell()

@property(nonatomic,assign)BOOL headImageHidden;

@end

@implementation VipInfpPersonTableViewCell

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    
    self  = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        /**
         类型图片
         */
        UIImageView *typeImageView  = [[UIImageView alloc] init];
        typeImageView.image = [UIImage imageNamed:@"login_9"];
        [self.contentView addSubview:typeImageView];
        self.typeImageView = typeImageView;
        
        /**
         头像
         */
        UIImageView *headImageView = [[UIImageView alloc] init];
        headImageView.backgroundColor = CSRedColor;
        //headImageView.contentMode = UIViewContentModeScaleAspectFill;
        headImageView.layer.masksToBounds = YES;
        headImageView.layer.cornerRadius = 4;
        headImageView.hidden = YES;
        [self.contentView addSubview:headImageView];
        self.headImageView = headImageView;
        
        
        /**
         类型名字
         */
        UILabel *typeLabel = [[UILabel alloc] init];
        typeLabel.font = MidFont;
        [self.contentView addSubview:typeLabel];
        self.typeLabel = typeLabel;
        
        
        
        /**
         详情
         */
        UILabel *detailLabel = [[UILabel alloc] init];
        detailLabel.font = MidFont;
        detailLabel.textColor = CSColorFromRGB(0x7a7a7a);
        [self.contentView addSubview:detailLabel];
        self.detailLabel = detailLabel;
        
        /**
         右侧图片
         */
        UIImageView *rightImageView = [[UIImageView alloc] init];
        rightImageView.image = [UIImage imageNamed:@"xiayibu"];
        [self.contentView addSubview:rightImageView];
        self.rightImageView = rightImageView;
        
        if ([reuseIdentifier isEqualToString:@"VipInfpPersonTableViewCellHeadView"]) {
        
            self.headImageHidden = NO;
            
            headImageView.hidden = NO;
            
        }
        else{
         
            self.headImageHidden = YES;
            
            headImageView.hidden = YES;
        }
        
        [self setConstraints];
    }
    
    return self;
}

-(void)setConstraints{
    
    /**
     类型图片
     */
    [self.typeImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(self.contentView).offset(10);
        
        if (self.headImageHidden) {
        
            make.top.mas_equalTo(self.contentView).offset(20);
            
            make.bottom.mas_equalTo(self.contentView).offset(-20);
        }
        else{
            
            make.centerY.mas_equalTo(self.contentView);
        }
    }];
    
    
    if (!self.headImageHidden) {
    
        /**
         头像
         */
        [self.headImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            
            make.right.mas_equalTo(self.rightImageView.mas_left).offset(-10);
            
            make.height.width.mas_equalTo(60);
            
            make.top.mas_equalTo(self.contentView).offset(15);
            
            make.bottom.mas_equalTo(self.contentView).offset(-15);
        }];
    }
    
    
    /**
     类型名字
     */
    [self.typeLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(self.typeImageView.mas_right).offset(10);
        
        make.centerY.mas_equalTo(self.contentView);
    }];
    
    /**
     详情
     */
    [self.detailLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.contentView);
        
        make.right.mas_equalTo(self.rightImageView.mas_left).offset(-10);
        
    }];
    
    /**
     右侧图片
     */
    [self.rightImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.centerY.mas_equalTo(self.contentView);
        
        make.right.mas_equalTo(self.contentView).offset(-10);
    }];
}

- (void)drawRect:(CGRect)rect
{
    CGContextRef context =UIGraphicsGetCurrentContext();
    
    CGContextBeginPath(context);
    
    CGContextSetLineWidth(context,1.0);//线宽度
    
    CGContextSetStrokeColorWithColor(context,LineBackGroundColor.CGColor);
    
    CGContextMoveToPoint(context,0,rect.size.height);
    
    CGContextAddLineToPoint(context,SCREEN_WIDTH,rect.size.height);
    
    CGContextStrokePath(context);
}

@end
